<template>
	<view class="integral-record ml-lg mr-lg">
		<view class="pt-lg pb-lg b-1px-b" v-for="(item,index) in list.data" :key="index">
			<view class="flex-between f-title c-title">
				<view>{{item.type_text}}</view>
				<view class="f-sm-title text-bold" :style="{color:item.integral_add*1 > 0?primaryColor:subColor}">
					{{item.integral_add*1 > 0 ? `+${item.integral_add}` : item.integral_add}}
				</view>
			</view>
			<view class="f-caption c-caption">{{item.create_time_text}}</view>
		</view>

		<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading" v-if="loading">
		</load-more>
		<abnor v-if="!loading&&list.data.length<=0&&list.current_page==1"></abnor>
		<view class="space-footer"></view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex';

	export default {
		components: {},
		data() {
			return {
				options: {},
				param: {
					page: 1,
				},
				list: {
					data: [],
					total: 0,
					current_page: 1,
					last_page: 1
				},
				loading: true
			}
		},
		computed: mapState({
			primaryColor: state => state.config.configInfo.primaryColor,
			subColor: state => state.config.configInfo.subColor,
		}),
		onLoad() {
			this.$util.showLoading()
			this.initIndex()
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			console.log(this.param.page)
			if (this.list.current_page >= this.list.last_page || this.loading) return
			this.param.page = this.param.page + 1
			this.loading = true
			this.getList()
		},
		methods: {
			initIndex() {
				this.getList()
			},
			initRefresh() {
				this.param.page = 1
				this.initIndex()
			},
			async getList() {
				let {
					list: oldList,
					param
				} = this
				let newList = await this.$api.shop.integralList(param);

				if (this.param.page == 1) {
					this.list = newList
				} else {
					newList.data = oldList.data.concat(newList.data)
					this.list = newList
				}
				this.loading = false
				this.$util.hideAll()
			}
		}
	}
</script>


<style lang="scss">
	page {
		background: #fff
	}
</style>
